package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.notice.domain.NoticeUser;
import com.ruoyi.notice.service.INoticeUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通知的用户Controller
 * 
 * @author 王强
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/notice/user")
public class NoticeUserController extends BaseController
{
    @Autowired
    private INoticeUserService noticeUserService;

    /**
     * 查询通知的用户列表
     */
    @PreAuthorize("@ss.hasPermi('notice:user:list')")
    @GetMapping("/list")
    public AjaxResult list(NoticeUser noticeUser)
    {
        List<NoticeUser> list = noticeUserService.selectList(noticeUser);
        return AjaxResult.success(list);
    }

    /**
     * 导出通知的用户列表
     */
    @PreAuthorize("@ss.hasPermi('notice:user:export')")
    @Log(title = "通知的用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NoticeUser noticeUser)
    {
        List<NoticeUser> list = noticeUserService.selectList(noticeUser);
        ExcelUtil<NoticeUser> util = new ExcelUtil<NoticeUser>(NoticeUser.class);
        util.exportExcel(response, list, "通知的用户数据");
    }

    /**
     * 获取通知的用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('notice:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(noticeUserService.selectById(id));
    }

    /**
     * 新增通知的用户
     */
    @PreAuthorize("@ss.hasPermi('notice:user:add')")
    @Log(title = "通知的用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NoticeUser noticeUser)
    {
        return toAjax(noticeUserService.insert(noticeUser));
    }

    /**
     * 修改通知的用户
     */
    @PreAuthorize("@ss.hasPermi('notice:user:edit')")
    @Log(title = "通知的用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NoticeUser noticeUser)
    {
        return toAjax(noticeUserService.update(noticeUser));
    }

    /**
     * 删除通知的用户
     */
    @PreAuthorize("@ss.hasPermi('notice:user:remove')")
    @Log(title = "通知的用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(noticeUserService.deleteByIds(ids));
    }
}
